package com.runda.task;

import java.io.InputStream;
import com.aliyun.oss.OSSClient;
import com.bbjob.mapper.VersionUpgradeMapper;
import com.bbjob.model.VersionUpgrade;

/**
 * 阿里云oss 版本升级专用文件流上传
 * @author Administrator
 *
 */
public class AliyunOssUploadFromInputStream extends Thread {
	private String endpoint;
	private String accessKeyId;
	private String accessKeySecret;
	private String key;
	private Integer id;
	private String bucket;
	private InputStream inputStream;
	private VersionUpgradeMapper versionMapper;
	@Override
	public void run() {
		try {
		    // 创建OSSClient实例
		    OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
		    ossClient.putObject(bucket, key, inputStream);
		    // 关闭client
		    ossClient.shutdown();
		  	VersionUpgrade version = new VersionUpgrade();
		  	version.setId(this.id);
		  	version.setFilePath(this.key);
		  	version.setVersionStatus(1);
		  	versionMapper.updateByPrimaryKeySelective(version);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			VersionUpgrade version = new VersionUpgrade();
		  	version.setId(this.id);
		  	version.setFilePath(this.key);
		  	version.setVersionStatus(-1);
		  	versionMapper.updateByPrimaryKeySelective(version);
		}
	}
	
	public AliyunOssUploadFromInputStream(String endpoint, String accessKeyId, String accessKeySecret, String key,
			Integer id, String bucket, InputStream inputStream, VersionUpgradeMapper versionMapper) {
		super();
		this.endpoint = endpoint;
		this.accessKeyId = accessKeyId;
		this.accessKeySecret = accessKeySecret;
		this.key = key;
		this.id = id;
		this.bucket = bucket;
		this.inputStream = inputStream;
		this.versionMapper = versionMapper;
	}
	
	
	
	
	
	
	

}
